#include <stdio.h>
int Partition(int a[], int l, int r)
{
    int i = l, j = r;
    int base = a[i];
    while (i < j)
    {
        while (j > i && a[j] >= base)
            j--;
        if (i < j)
        {
            a[i] = a[j];
            i++;
        }
        while (i < j && a[i] <= base)
            i++;
        if (i < j)
        {
            a[j] = a[i];
            j--;
        }
    }
    a[i] = base;
    return i;
}

void QuickSort(int a[], int l, int r)
{
    int i;
    if (l < r)
    {
        i = Partition(a, l, r);
        QuickSort(a, l, i - 1);
        QuickSort(a, i + 1, r);
    }
}

int main()
{
    int a[] = {9, 5, 6, 4, 8, 3, 0, 1, 7, 2};
    int len = sizeof(a) / sizeof(a[0]);
    QuickSort(a, 0, len - 1);
    for (int i = 0; i < len; i++)
        printf("%d ", a[i]);
    return 0;
}